package cn.tedu._08security.config;

import cn.tedu._08security.service.userdetailsserviceimpl;
import org.springframework.context.annotation.Bean;
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.web.SecurityFilterChain;
import org.springframework.stereotype.Component;
@EnableGlobalMethodSecurity(prePostEnabled = true)
@Component
public class security {

    @Bean
    public userdetailsserviceimpl userdetailsservice()
    {
        return new userdetailsserviceimpl();
    }
    @Bean
    public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
        http.authorizeHttpRequests(authorize->authorize
                .requestMatchers("/api/public").permitAll()
                .anyRequest().authenticated())
                .formLogin(from->from.permitAll())
                .logout(logout->logout.permitAll());
        return http.build();
    }
    @Bean
    public SecurityFilterChain filterchain(HttpSecurity http) throws Exception
    {
        http.authorizeHttpRequests(authorize->authorize.requestMatchers("api/public").permitAll().anyRequest().authenticated())
                .formLogin(from->from.permitAll())
                .logout(logout->logout.permitAll());
        return http.build();
    }
}
